package com.epoint.springboot.controller;

import com.epoint.springboot.bean.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * springboot的简单Demo
 * Created by wangchao on 2017/10/8.
 */


@RestController
@RequestMapping(value = "/index")
public class IndexController {

    //读取配置文件信息
    @Value(value = "${roncoo.secret}")
    private String secret;

    @Value(value = "${roncoo.number}")
    private int id;

    @Value(value = "${roncoo.desc}")
    private String desc;

    @RequestMapping
    public String index() {
        return "hello world";
    }

    //@RequestParam 简单类型的绑定，可以出来get和post   http://localhost:8090/index/get?name=王超
    @RequestMapping(value = "get")
    public Map<String, Object> get(@RequestParam String name) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("title", "hello world");
        map.put("name", name);
        map.put("secret", secret);
        map.put("id", id);
        map.put("desc", desc);
        return map;
    }

    // @PathVariable 获得请求url中的动态参数
    @RequestMapping(value = "find/{id}/{name}")
    public User get(@PathVariable int id, @PathVariable String name) {
        User u = new User();
        u.setId(id);
        u.setName(name);
        u.setDate(new Date());
        return u;
    }
}
